<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>17.自定义find原型方法实现</title>
</head>
<body>
  <script>
    function find(array,callback) {
      for(const value of array) {
          if(callback(value))
            return value;
          
      }
      return undefined;
    }
    let arr = [1,2,3,4,5];
    console.log(find(arr,function(item){
      return item == 2;
    }));
    //添加原型方法实现
    Array.prototype.findValue = function(callback) {
      for(const value of this) {
        if(callback(value)) return value;
      }
      return undefined;
    }
    const res = arr.findValue(function(item) {
      return item == 223;
    })
    console.log(res);
  </script>
</body>
</html>